package com.whzm.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whzm.mapper.MemberInfoMapper;
import com.whzm.mapper.MemberTypeMapper;
import com.whzm.pojo.MemberInfo;
import com.whzm.pojo.MemberType;
import com.whzm.service.MemberBack;
import com.whzm.util.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MemberBackImpl implements MemberBack {
    @Autowired
    MemberInfoMapper memberInfoMapper;
    @Autowired
    MemberTypeMapper memberTypeMapper;

    /**获取会员信息*/
    @Override
    @Transactional(readOnly = true)
    public ResponseEntity getMember(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        //执行查询
        List<MemberInfo> lists=memberInfoMapper.getlist();
        //取出总共多少条数据，使用分页实体类取
        PageInfo pageInfo=new PageInfo(lists);
        //数据封装
        return ResponseEntity.pageInfo(0,"0",lists, pageInfo.getTotal());
    }

    /**获取会员类型信息*/
    @Override
    @Transactional(readOnly = true)
    public ResponseEntity getMemberType(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        //执行查询
        List<MemberType> lists=memberTypeMapper.getlist();
        //取出总共多少条数据，使用分页实体类取
        PageInfo pageInfo=new PageInfo(lists);
        //数据封装
        return ResponseEntity.pageInfo(0,"",lists, pageInfo.getTotal());
    }

    /**删除会员类型信息*/
    @Override
    public ResponseEntity updateMemberType(String id, Integer isDeleted) {
        MemberType newMemberType=new MemberType();
        newMemberType.setId(id);
        newMemberType.setIsDeleted(isDeleted);
        int i=memberTypeMapper.updateById(newMemberType);
        if(i==1){
            return ResponseEntity.tipsSuccess(1,"操作成功");
        }
        return ResponseEntity.tipsSuccess(0,"操作失败");
    }
    /**修改会员类型信息*/
    @Override
    public ResponseEntity updateMemberType(MemberType memberType) {
        int i=memberTypeMapper.updateById(memberType);
        if(i==1){
            return ResponseEntity.tipsSuccess(1,"操作成功");
        }
        return ResponseEntity.tipsSuccess(0,"操作失败");
    }
}
